#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <iostream>
#include <math.h>

#include "HoleBlock.h"

// Material Properties
GLfloat holeBlock_diffuse[] = {0.50, 0.50, 0.50, 1.0};

HoleBlock::HoleBlock(void) {
	topWidth = 1.0;
	topLength = 0.5;
	topHeight = 0.25;
	botWidth = 1.0;
	botLength = 0.5;
	botHeight = 0.25;
	leftWidth = 1.0;
	leftLength = 0.25;
	leftHeight = 1.0;
	rightWidth = 1.0;
	rightLength = 0.25;
	rightHeight = 1.0;
	loadImage();
}

//function to load the images to use as textures
void HoleBlock::loadImage() {
	Image* image1 = loadBMP("textures\\rock.bmp");
	Image* image2 = loadBMP("textures\\wood.bmp");
	blockTexture = loadTexture(image1);
	sideTexture = loadTexture(image2);
	delete image1;
	delete image2;
}

void HoleBlock::display() {
	glPushMatrix();
		glMaterialfv(GL_FRONT, GL_DIFFUSE, holeBlock_diffuse);
		glTranslatef(0, 1.37, 0);
		glColor3f(1,1,1);
		glPushMatrix();
			//create the texture for the top of the block, set to 'stone'
			glBindTexture(GL_TEXTURE_2D, blockTexture);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			//top block
			glScalef(topLength, topHeight, topWidth);
			glColor3f(0.5, 0.5, 0.5);
			drawCube();
			//glutSolidCube(1.0);
		glPopMatrix();

		glPushMatrix();
			//create the texture for the left block, set to 'stone'
			glBindTexture(GL_TEXTURE_2D, sideTexture);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			//leftblock
			glTranslatef(-topLength/1.33, -topHeight*1.5, 0.0);
			glScalef(leftLength, leftHeight, leftWidth);
			glColor3f(0.5, 0.5, 0.5);
			drawCube();
			//glutSolidCube(1.0);
		glPopMatrix();

		glPushMatrix();
			//create the texture for the right block, set to 'stone'
			glBindTexture(GL_TEXTURE_2D, sideTexture);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			//right block
			glTranslatef(topLength/1.33, -topHeight*1.5, 0.0);
			glScalef(rightLength, rightHeight, rightWidth);
			glColor3f(0.5, 0.5, 0.5);
			drawCube();
			//glutSolidCube(1.0);
		glPopMatrix();

		glPushMatrix();
			//create the texture for the bottom of the block, set to 'stone'
			glBindTexture(GL_TEXTURE_2D, blockTexture);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
			//bottom block
			glTranslatef(0.0, -topHeight*3, 0.0);
			glScalef(botLength, botHeight, botWidth);
			glColor3f(0.5, 0.5, 0.5);
			drawCube();
			//glutSolidCube(1.0);
		glPopMatrix();


		/*glPushMatrix();
			glTranslatef(0.0, -topHeight/2, -topWidth/2);
			glBegin(GL_QUADS);
				glColor3f(0.3, 0.3, 0.3);
				glVertex3f(-topLength/2, 0.0, 0.0);
				glVertex3f(topLength/2, 0.0, 0.0);
				glVertex3f(topLength/2, -topHeight*2, 0.0);
				glVertex3f(-topLength/2, -topHeight*2, 0.0);
			glEnd();
		glPopMatrix();*/
		//drawCube(0.5, 0.5);
	glPopMatrix();
}

HoleBlock::~HoleBlock(void) {}